<template>
	<view class="" v-if="pageShow">
		<view class="" style="padding: 30rpx 30rpx 0;">
			<view class="hybox">
				<view class="flexleft">
					<image class="touxiang margin_right2" :src="userInfo.avatar_text" mode=""></image>
					<view class="bigtext xiaobai">{{userInfo.nickname}}</view>
				</view>
				<view class="flexbetween margin_top">
					<view class="ershiba" style="color:#DCDCDC ;">
						{{userInfo.level==0?"暂未开通":userInfo.level==1?"普通会员 "+userInfo.vip_time_text+"到期":"vip会员 "+userInfo.vip_time_text+"到期"}}</view>
					<view class="flexright" @click="jumper('/pages_mypage/huiyuanjl')">
						<view class="ershiba margin_right2" style="color:#DCDCDC ;">记录</view>
						<u-icon name="arrow-right" color="#FFFFFF" size="14"></u-icon>
					</view>
				</view>
			</view>
		</view>
		<view class="block mainpadding">
			<!-- <u-tabs :list="list1" lineColor="#DD5056" :scrollable="false" @change="tabschange" :activeStyle="{
				    color: '#FFFFFF',
				    fontWeight: 'bold',
				    transform: 'scale(1.05)'
				}" :inactiveStyle="{
				            color: '#999999',
							fontWeight: '500',
				            transform: 'scale(1)'
				        }" itemStyle="height: 44px;"></u-tabs> -->
			<view class="sanshier xiaobai fonweight margin_top">尊享权益</view>
			<!-- <view class="ershiba xiaobai margin_top" v-if="tabsid==1">可查看所有免费视频</view> -->
			<view class="ershiba xiaobai margin_top" v-if="tabsid==2">可查看所有视频</view>
			<view class="margin_top">
				<!-- <scroll-view class="scroll-view_H" scroll-x="true" v-if="tabsid==1">
					<view class="scroll-view-item_H uni-bg-green margin_right2" v-for="item in levelList1"
						:key="item.id" @click="card_id=item.id">
						<view class="weixbtn" :class="card_id==item.id?'yixbtn':'weixbtn'">
							<view class="bigtext  textcenter" :class="card_id==item.id?'xiaobai':'xiaohui'">{{item.name}}</view>
							<view class="titletext fonweight" :class="card_id==item.id?'xiaobai':'xiaohui'">￥
								<text class="  fonweight" :class="card_id==item.id?'xiaobai':'xiaohui'"
									style="font-size: 42rpx;">{{item.price}}</text>
							</view>
						</view>
					</view>
				</scroll-view> -->
				<scroll-view class="scroll-view_H" scroll-x="true" v-if="tabsid==2">
					<view class="scroll-view-item_H uni-bg-green margin_right2" v-for="item in levelList2"
						:key="item.id" @click="card_id=item.id">
						<view class="weixbtn" :class="card_id==item.id?'yixbtn':'weixbtn'">
							<view class="bigtext  textcenter" :class="card_id==item.id?'xiaobai':'xiaohui'">{{item.name}}</view>
							<view class="titletext fonweight" :class="card_id==item.id?'xiaobai':'xiaohui'">￥
								<text class="  fonweight" :class="card_id==item.id?'xiaobai':'xiaohui'"
									style="font-size: 42rpx;">{{item.price}}</text>
							</view>
						</view>
					</view>
				</scroll-view>
			</view>
		</view>
		<view class="gudingdb mainpadding">
			<view class="bigbtn" @click="submit()">立即购买</view>
		</view>
	</view>
</template>

<script>
	const httpRequest = require("@/common/httpRequest.js")

	export default {
		data() {
			return {
				list1: [{
						name: '普通会员',
						id:1
					},
					{
						name: 'VIP会员',
						id:2
					}
				],
				tabsid:2,
				userInfo: {},
				pageShow: false,
				levelList1: [],
				levelList2: [],
				card_id: "",
			}
		},
		onLoad() {
			this.init()
			this.getlist()
		},
		methods: {
			submit(){
				if(this.card_id==""){
					httpRequest.toast("请选择会员类型")
					return false
				}
				uni.showLoading({
					mask:true,
					title:"请稍后"
				})
				httpRequest.request('/api/cardcl/create_order', 'GET', {
					card_id:this.card_id
				}, false, false, true).then(res => {
					uni.hideLoading()
					httpRequest.toast(res.msg)
					if(res.code==1){
						setTimeout(()=>{
							uni.navigateBack(1)
						},1000)
					}
				})
			},
			init() {
				httpRequest.request('/api/user/index', 'GET', {}, false, false, true).then(res => {
					this.userInfo = res.data
					this.pageShow = true
				}).catch(err => {
					httpRequest.toast(err.msg);
				})
			},
			getlist() {
				httpRequest.request('/api/cardcl/cardIndex', 'GET', {
					level: 1,
				}, false, false, true).then(res => {
					this.levelList1 = res.data
				})
				httpRequest.request('/api/cardcl/cardIndex', 'GET', {
					level: 2,
				}, false, false, true).then(res => {
					this.levelList2 = res.data
				})
			},
			tabschange(e){
				this.tabsid=e.id
			},
			jumper(url) {
				uni.navigateTo({
					url: url
				})
			},
			upper: function(e) {
				console.log(e)
			},
			lower: function(e) {
				console.log(e)
			},
			scroll: function(e) {
				console.log(e)
				this.old.scrollTop = e.detail.scrollTop
			},
			goTop: function(e) {
				// 解决view层不同步的问题
				this.scrollTop = this.old.scrollTop
				this.$nextTick(function() {
					this.scrollTop = 0
				});
				uni.showToast({
					icon: "none",
					title: "纵向滚动 scrollTop 值已被修改为 0"
				})
			}
		}
	}
</script>

<style lang="scss" scoped>
	// .scroll-Y {
	// 	height: 300rpx;
	// }

	// .scroll-view_H {
	// 	white-space: nowrap;
	// 	width: 100%;
	// }

	// .scroll-view-item {
	// 	height: 300rpx;
	// 	line-height: 300rpx;
	// 	text-align: center;
	// 	font-size: 36rpx;
	// }

	// .scroll-view-item_H {
	// 	display: inline-block;
	// 	width: 100%;
	// 	height: 300rpx;
	// 	line-height: 300rpx;
	// 	text-align: center;
	// 	font-size: 36rpx;
	// }

	.weixbtn {
		padding: 40rpx 35rpx;
		background: rgba(177, 177, 177, 0.1);
		border-radius: 17rpx 17rpx 17rpx 17rpx;
	}

	.yixbtn {
		padding: 40rpx 35rpx;
		background: #DD5056;
		border-radius: 17rpx 17rpx 17rpx 17rpx;
	}

	.block {
		background: #282536;
		box-shadow: 0rpx 4rpx 12rpx 0rpx rgba(0, 0, 0, 0.02);
		border-radius: 36rpx 36rpx 0rpx 0rpx;
	}

	.touxiang {
		width: 74rpx;
		height: 74rpx;
		border-radius: 50%;
	}

	.hybox {
		background-size: 100% 100%;
		padding: 25rpx 40rpx 30rpx 56rpx;
		background-image: url('../static/image/sysem/hybjt.png');
	}
</style>